﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class per_together : MpageBase
{
    protected Model.UsersAccount user_account = null;
    protected Model.CMember CMember = null;
    protected List<Model.LotteryChipped> buyInfo = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
            bindData();
        }
    }
    private void Bind()
    {
        if (loginUserInfo != null && loginUserInfo.Id > 0)
        {
            user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
            CMember = BLL.CMember.GetModel(loginUserInfo.Id);
            if (user_account == null)
            {
                BLL.Session.Remove(BLL.CMember.LoginUserSessionKey);
                Response.Redirect("/default.aspx");
            }
        }
        else
        {
            Response.Redirect("/default.aspx");
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
    protected void bindData()
    {
        //Bind();
        PagedDataSource pds = new PagedDataSource();
        string sql = "";
        string where = "";
        int type = int.Parse(this.typeslddl.SelectedValue);//彩种类型
        if (this.myhm.Checked)//我发布的
        {
            if (type > 0)
            {

                sql = "select * from LotteryChipped  where UserID=" + loginUserInfo.Id + " and LotteryChipped.LotteryType=" + type;
            }
            else
            {

                sql = "select * from LotteryChipped  where UserID=" + loginUserInfo.Id;
            }
        }
        else if (this.cyhm.Checked)//我参与的
        {
            if (type > 0)
            {
                //sql = "select   Name,Describe,Commission,MyGua,LotteryNo,LotteryPlay,LotteryWinMoney,LotteryYE,IsOpen,WinLevel,getalltime,fcType,fcTypeNext,secret,Credit,ProjectStatus,LotteryMultiple,LotteryCount,l.AddTime as AddTime,LotteryOpenTime,l.UserID as UserID,LotteryMoney,LotteryJD,State,l.Flag as Flag,l.IsWin as IsWin,l.WinMoney as WinMoney,l.id as id,LotteryType, convert(int,LotteryChippedUser.MySub) MySub,LotteryChippedUser.UserID as jionUserId,LotteryChippedUser.AddTime as userAddtime from LotteryChipped l join LotteryChippedUser on l.id=LotteryChippedUser.LotteryChippedID "
                //    + "where LotteryChippedUser.UserID=" + loginUserInfo.Id + " and l.LotteryType=" + type;
                sql = "select   Name,Describe,Commission,MyGua,LotteryNo,LotteryPlay,LotteryWinMoney,LotteryYE,IsOpen,WinLevel,getalltime,  ";
                sql += "fcType,fcTypeNext,secret,Credit,ProjectStatus,LotteryMultiple,LotteryCount,l.AddTime as AddTime,LotteryOpenTime, ";
                sql += "l.UserID as UserID,LotteryMoney,LotteryJD,State,l.Flag as Flag,l.IsWin as IsWin,LotteryChippedUser.WinMoney as WinMoney,l.id as id, ";
                sql += "LotteryType, convert(int,LotteryChippedUser.MySub) MySub,LotteryChippedUser.UserID as jionUserId,LotteryChippedUser.AddTime as userAddtime  ";
                sql += "from LotteryChipped l join LotteryChippedUser on l.id=LotteryChippedUser.LotteryChippedID  ";
                sql += " where l.UserID <> LotteryChippedUser.UserID and LotteryChippedUser.UserID = " + loginUserInfo.Id + " and l.LotteryType=" + type;
            }
            else
            {

                //sql = "select  Name,Describe,Commission,MyGua,LotteryNo,LotteryPlay,LotteryWinMoney,LotteryYE,IsOpen,WinLevel,getalltime,fcType,fcTypeNext,secret,Credit,ProjectStatus,LotteryMultiple,LotteryCount,l.AddTime as AddTime,LotteryOpenTime,l.UserID as UserID,LotteryMoney,LotteryJD,State,l.Flag as Flag,l.IsWin as IsWin,l.WinMoney as WinMoney,l.id as id,LotteryType, convert(int,LotteryChippedUser.MySub) MySub,LotteryChippedUser.UserID as jionUserId,LotteryChippedUser.AddTime as userAddtime from LotteryChipped l join LotteryChippedUser on l.id=LotteryChippedUser.LotteryChippedID "
                //    + "where LotteryChippedUser.UserID <>" + loginUserInfo.Id;
                sql = "select   Name,Describe,Commission,MyGua,LotteryNo,LotteryPlay,LotteryWinMoney,LotteryYE,IsOpen,WinLevel,getalltime,  ";
                sql += "fcType,fcTypeNext,secret,Credit,ProjectStatus,LotteryMultiple,LotteryCount,l.AddTime as AddTime,LotteryOpenTime, ";
                sql += "l.UserID as UserID,LotteryMoney,LotteryJD,State,l.Flag as Flag,l.IsWin as IsWin,LotteryChippedUser.WinMoney as WinMoney,l.id as id, ";
                sql += "LotteryType, convert(int,LotteryChippedUser.MySub) MySub,LotteryChippedUser.UserID as jionUserId,LotteryChippedUser.AddTime as userAddtime  ";
                sql += "from LotteryChipped l join LotteryChippedUser on l.id = LotteryChippedUser.LotteryChippedID  ";
                sql += " where l.UserID <>LotteryChippedUser.UserID and LotteryChippedUser.UserID =  " + loginUserInfo.Id;
            }
        }
        else
        {

            if (type > 0)
            {
                sql = "select * from LotteryChipped  where UserID=" + loginUserInfo.Id + " and LotteryChipped.LotteryType=" + type;
            }
            else
            {

                sql = "select * from LotteryChipped  where UserID <>" + loginUserInfo.Id;
            }
        }
        int times = int.Parse(this.timesl.SelectedValue.ToString());
        if (times == 0)
        {
            where += " and datediff(day,[AddTime],getdate())=0 ";
        }
        else if (times == 1)
        {
            where += " and datediff(week,[AddTime],getdate())=0 ";
        }
        else if (times == 2)
        {
            where += " and datediff(month,[AddTime],getdate())=0";
        }
        else if (times == 3)
        {
            where += " and datediff(month,[AddTime],getdate())<=3 ";
        }
        else if (times == 4)
        {
            where += " and datediff(month,[AddTime],getdate())<=6 ";
        }
        //是否中奖
        if (CheckBox1.Checked)
        {
            where += " and IsWin=1";
        }
        if (CheckBox3.Checked)
        {
            where += " and IsWin=0";
        }

        //是否开奖
        if (CheckBox2.Checked)
        {
            where += " and Flag=0";
        }
        int totalCount = 0;
        //buyInfo = BLL.LotteryChippedUser.GetPageListBysql(sql);
        DataTable datatable = BLL.LotteryChipped.GetPageListBysql(sql + " order by id desc");
        //buyInfo = BLL.LotteryChipped.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, where, out totalCount);
        buyInfo = BLL.LotteryChipped.GetPageListBysqlfrom(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, " 1=1 " + where, "(" + sql + ") t");
        if (buyInfo != null && buyInfo.Count > 0)
        {
            AspNetPager1.Visible = true;
            AspNetPager1.RecordCount = datatable.Rows.Count;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        }
        else
        {
            AspNetPager1.Visible = false;
            //AspNetPager1.RecordCount = 0;
            //pds.AllowPaging = true;
            //pds.PageSize = AspNetPager1.PageSize;
            //pds.CurrentPageIndex = 1;
        }
    }
    protected void myhm_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
    protected void cyhm_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
    protected void typeslddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
    public string select(object userid)
    {
        Model.CMember cm = null;
        cm = BLL.CMember.GetModel(long.Parse(userid.ToString()));
        return cm != null ? cm.nickname : "暂无姓名";
    }
    protected void timesl_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }

    protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
    {
        Bind();
        bindData();
    }
}